import { MSG_TYPE } from "@/pages/home/config";
import { IAiPicItem, IMessageItem } from "./type";
import { MsgBase } from "./Base";
import { MessageWait } from "./MessageWait";
import { MessagePic } from "./MessagePic";
import { MessageFail } from "./MessageFail";
import { MessagePresets } from "./MessagePreset";
import { IDesItem } from "@/types";
import './index.scss'
interface IMessageProps {
    isH5?: boolean;
    message: IMessageItem;
    index: number;
    presets: IDesItem[];
    onSelectPreset: (preset: IDesItem) => void;
    onToParent: (id: string) => void
    onCloseJob: (msg:IMessageItem,index:number) => void;
    onGetHighPic: (pic: IAiPicItem, msg: IMessageItem) => void
    onToEdit:(pic:IAiPicItem)=>void
    onReStart: (message: IMessageItem, index: number) => void
    onRefreshPresets:()=>void
}
export function MessageItem(props:IMessageProps)  { 
    const { message,presets,onGetHighPic,onToParent,onReStart ,onToEdit,onCloseJob,onSelectPreset,onRefreshPresets,index,isH5} = props
    const isTextBase = message.type === MSG_TYPE.BASE
    const isWaiting = [MSG_TYPE.WATTING, MSG_TYPE.GENERATING].includes(message.type) 
    const isFinish = MSG_TYPE.FINISH === message.type
    const isError = [MSG_TYPE.ERROR,MSG_TYPE.PROHIBIT,MSG_TYPE.CANCEL].includes(message.type)
    return (
        <MsgBase message={message} onToParent={onToParent}>
            {
                isTextBase ? <MessagePresets isH5={ isH5} presets={presets} onSelectPreset={onSelectPreset} onRefreshPresets={onRefreshPresets}></MessagePresets>  :
                    isWaiting ? <MessageWait onCloseJob={(msg) => { 
                        onCloseJob(msg,index)
                    }} message={message}></MessageWait> :
                        isFinish ? <MessagePic isH5={ isH5} onToEdit={ onToEdit} message={message} onCheckHighPic={(pic) => { 
                        onGetHighPic(pic,message)
                        }}></MessagePic> :
                            isError ? <MessageFail onReStart={() => { 
                                onReStart && onReStart(message,index)
                            }} message={message}></MessageFail> : null
            }
        </MsgBase> 
    )
}